﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BaseData;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BaseData.Company;
using WaterRevenueMS.Componnent.Common;

namespace WaterRevenueMS.Core.Service.BaseData.Impl
{
    [Export(typeof(ICompanyService))]
    public class CompanyService : CoreServiceBase, ICompanyService
    {
        [Import]
        public ICompanyRepository CompanyRepository { get; set; }

        public IQueryable<CompanySet> Companys
        {
            get{return CompanyRepository.Entities;}
        }

        public OperationResult Insert(CompanyModel model)
        {
            var entity = new CompanySet
            {
              //  Name = model.Name,
             //   ParentId = model.ParentId != 0 ? model.ParentId : null
            };
            CompanyRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(CompanyModel model)
        {
            var entity = new CompanySet
            {
           //     Id=model.Id,
        //        Name=model.Name,
          //      ParentId=model.ParentId!=0?model.ParentId:null
            };
            CompanyRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var model = Companys.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;
            CompanyRepository.Update(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
